using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ClientMain : MonoBehaviour
{
    [SerializeField]
    string ip = "127.0.0.1";
    [SerializeField]
    int port = 8900;

    public void Awake()
    {
        NetManager.Instance.Awake();
    }

    private void OnEnable()
    {
        EventDispatchManager.Instance.AddEvent(EventId.Game.EVENT_PLAYER_OUTLOGIN, OnPlayerOutLogin);
    }

    private void OnDisable()
    {
        EventDispatchManager.Instance.RemoveEvent(EventId.Game.EVENT_PLAYER_OUTLOGIN, OnPlayerOutLogin);
    }

    public void Connected()
    {
        ClientNetManager.Create(ip,port,9527);
    }

    public void Update()
    {
        NetManager.Instance.Update();
    }

    void OnPlayerOutLogin(IEventArgv eventArgv)
    {
        NetManager.Instance.Destroy();
        ClientNetManager.Destroy();
        NetManager.Instance.Awake();
    }

    public void OnDestroy()
    {
        NetManager.Instance.Destroy();
    }
}
